import { defineStore } from 'pinia';
import { fate } from '@/services/apis';
import dayjs from "dayjs";
import { isEmpty } from "lodash";
import { useUserStore } from './user';

// @ts-ignore
export const useFateStore = defineStore('fate', {
    state: () => {
        return {

        };
    },
    getters: {

    },
    actions: {
        async queryTodayFate(params: any) {
            const userStore = useUserStore()
            const { date = '' } = params;
            const queryFate = dayjs(date).isSame(dayjs(), 'day') ? fate.today({}) : fate.history({ date: dayjs(date).format('YYYYMMDD') })
            const requests = [queryFate, fate.calendar({ date: dayjs(userStore.userInfo?.solarBirthday).format('YYYY-MM-DD') })]
            const res = await Promise.all(requests)
            const [fateInfo = {}, personalInfo = {}] = res
            if (isEmpty(fateInfo)) {
                uni.showToast({
                    title: '只能查询注册日期之后的运势',
                    icon: 'none',
                });
            }
            return { fateInfo, personalInfo }
        },
    },
});
